#include "connection.h"
using namespace ns_conn;

void cb(Channel::ptr chp, const std::string &tag,
        const ns_proto::Attributes *att, const std::string &body)
{
    cout << "consume_tag:" << tag << " recive message:" << body << endl;
    chp->basicAck(att->id());
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "usage: ./consume_client queue_name\n";
        return -1;
    }

    AsyncWorker::ptr wp = make_shared<AsyncWorker>();
    Connection::ptr conptr = make_shared<Connection>("127.0.0.1", 8888, wp);

    Channel::ptr cp = conptr->createChannel();

    google::protobuf::Map<std::string, std::string> args;

    cp->declareExchange("e1", TOPIC, true, false, args);
    cp->declareQueue("q1", true, false, false, args);
    cp->declareQueue("q2", true, false, false, args);
    cp->queueBind("e1", "q1", "sport.#");
    cp->queueBind("e1", "q2", "sport.basketball");
    cp->basicConsum("consume1", argv[1], false, std::bind(cb, cp, _1, _2, _3));

    while (1)
    {
        sleep(3);
    }

    return 0;
}